package com.ruoyi.web.controller.room;

import com.cdtu.room.domain.Notification;
import com.cdtu.room.service.INotificationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 提醒与通知Controller
 * 
 * @author hcc
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/room/notification")
public class NotificationController extends BaseController
{
    @Autowired
    private INotificationService notificationService;

    /**
     * 查询提醒与通知列表
     */
    @PreAuthorize("@ss.hasPermi('room:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notification notification)
    {
        startPage();
        List<Notification> list = notificationService.selectNotificationList(notification);
        return getDataTable(list);
    }

    /**
     * 导出提醒与通知列表
     */
    @PreAuthorize("@ss.hasPermi('room:notification:export')")
    @Log(title = "提醒与通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notification notification)
    {
        List<Notification> list = notificationService.selectNotificationList(notification);
        ExcelUtil<Notification> util = new ExcelUtil<Notification>(Notification.class);
        util.exportExcel(response, list, "提醒与通知数据");
    }

    /**
     * 获取提醒与通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('room:notification:query')")
    @GetMapping(value = "/{notificationId}")
    public AjaxResult getInfo(@PathVariable("notificationId") Long notificationId)
    {
        return success(notificationService.selectNotificationByNotificationId(notificationId));
    }

    /**
     * 新增提醒与通知
     */
    @PreAuthorize("@ss.hasPermi('room:notification:add')")
    @Log(title = "提醒与通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notification notification)
    {
        return toAjax(notificationService.insertNotification(notification));
    }

    /**
     * 修改提醒与通知
     */
    @PreAuthorize("@ss.hasPermi('room:notification:edit')")
    @Log(title = "提醒与通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notification notification)
    {
        return toAjax(notificationService.updateNotification(notification));
    }

    /**
     * 删除提醒与通知
     */
    @PreAuthorize("@ss.hasPermi('room:notification:remove')")
    @Log(title = "提醒与通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notificationIds}")
    public AjaxResult remove(@PathVariable Long[] notificationIds)
    {
        return toAjax(notificationService.deleteNotificationByNotificationIds(notificationIds));
    }
}
